package com.rc.activity.sync.util;

import java.util.ArrayList;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;

import com.rc.activity.dao.DaoSession;
import com.rc.activity.dao.tbl_Profile;
import com.rc.activity.dao.tbl_ProfileDao;

public class ProfileSync {

	private Context context;
	private SQLiteDatabase db;
	private DaoSession daoSession;
	public String query;
	private tbl_ProfileDao daoProfile;
	public Cursor cursor;

	public ProfileSync(Context context, SQLiteDatabase db, DaoSession daoSession) {
		this.context = context;
		this.daoSession = daoSession;
		this.db = db;
		daoProfile = this.daoSession.getTbl_ProfileDao();
	}
	/**
	 * Update profile
	 */
	public void updateProfile(){
		new callUpdateProfile().execute("");
	}

	/**
	 * call update profile
	 */
	private class callUpdateProfile extends
			AsyncTask<String, Void, ArrayList<Long>> {

		@Override
		protected ArrayList<Long> doInBackground(String... params) {
			// The string name is query, providing that "isDelete" = 1
			query = tbl_ProfileDao.Properties.IsUpdate.columnName + " = '1'";
			Long profileID;

			// get data in sqlite
			cursor = db.query(daoProfile.getTablename(),
					daoProfile.getAllColumns(), query, null, null, null, null);
			tbl_Profile profile = new tbl_Profile();

			// get ArrayList Merchant by cursor
			profile = tbl_Profile.getObjectbyCursor(cursor);
			// query server
//			if (NetSupport.delete_receipt(arrMerchantID)) {
//				return arrMerchantID;
//			}
			return null;

		}

		protected void onPostExecute(ArrayList<Long> arrMerchantID) {
			if (arrMerchantID != null) {

			}
		}
	}
}
